package com.kunbo.cn.service.impl.core.message;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import com.kunbo.cn.dao.core.inventory.InventoryDao;
import com.kunbo.cn.dao.core.message.LeavingMessageDao;
import com.kunbo.cn.entity.core.inventory.Inventory;
import com.kunbo.cn.entity.core.message.LeavingMessage;
import com.kunbo.cn.service.core.message.LeavingMessageService;

/**
 *
 * @author bjl  
 * @date 2019年4月25日 
 */
@Service
public class LeavingMessageServiceImpl implements LeavingMessageService {
	@Autowired
	private LeavingMessageDao dao;
	@Autowired
    private JdbcTemplate jdbcTemplate;
	@Override
	public void save(LeavingMessage mes) {
		dao.save(mes);
		
	}
	
	
	@Override
	public void delete(String id) {
		dao.delete(id);
	}
	
	@Override
	public LeavingMessage findById(String id) {
		return dao.findOne(id);
	}
	
	/*@Override
	public void updateSate(OrderCarryOver carryOver) {
		dao.save(carryOver);
	}*/
	/**
	 * 分页条件列表查询
	 */
	@Override
	public Page<LeavingMessage> findLeavingMessage(Integer pageNo, Integer pageSize) {
		Pageable pageable = new PageRequest(pageNo-1, pageSize);
        Specification<LeavingMessage> confusion=new Specification<LeavingMessage>() {
            @Override
            public Predicate toPredicate(Root<LeavingMessage> root, CriteriaQuery<?> query,
                    CriteriaBuilder criteriaBuilder) {
            	List<Predicate> predicates = new ArrayList<>();
            	/*if(!"".equals(materType)) {
            		predicates.add(criteriaBuilder.like(root.get("materType"), "%"+materType+"%"));
            	}
            	if(!"".equals(curentDate)) {
            		predicates.add(criteriaBuilder.like(root.get("curentDate"), "%"+curentDate+"%"));
            	}*/
                return criteriaBuilder.and(predicates.toArray(new Predicate[predicates.size()]));
            }
        };
        return dao.findAll(confusion, pageable);
	}

}
